local extension = Package:new("starjade_generals_cards", Package.CardPack)
extension.extensionName = "zzz_zyg_cards"
Fk:loadTranslationTable{
  ["starjade_generals_cards"] = "星玉额外牌堆",
}

local slash = Fk:cloneCard("slash")
local rockSlashSkill = fk.CreateActiveSkill{
  name = "rock__slash_skill",
  max_phase_use_time = 1,
  target_num = 1,
  can_use = slash.skill.canUse,
  mod_target_filter = slash.skill.modTargetFilter,
  target_filter = slash.skill.targetFilter,
  on_effect = function(self, room, effect)
    local to = effect.to
    local from = effect.from
    room:damage({
      from = room:getPlayerById(from),
      to = room:getPlayerById(to),
      card = effect.card,
      damage = 1,
      damageType = "rock_damage",
      skillName = self.name
    })
  end
}
local RockDamageSkill = fk.CreateTriggerSkill{
  name = "rock_damage_skill",
  global = true,
  priority = 0,
  mute = true,
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if target == player and data.card and not data.chain then
      return data.damage > 0 and data.damageType == "rock_damage" 
    end
  end,
  on_cost = function (self, event, target, player, data)
    local to = data.to
    local num = 2 * data.damage
    if not to.dead and #to:getCardIds { Player.Hand, Player.Equip } > data.damage then
      local cards = player.room:askForDiscard(to, num, num, true, self.name, true, nil, "#rock_damage-ask:::"..num)
      if #cards >= num then
        return true
      end
    end
    return 
  end,
  on_use = function(self, event, target, player, data)
    return true
  end,
}
Fk:addSkill(RockDamageSkill)
local rockSlash = fk.CreateBasicCard{
  name = "rock__slash",
  skill = rockSlashSkill,
  is_damage_card = true,
  suit = Card.Diamond,
  number = 13,
}
extension:addCards{
  rockSlash:clone(Card.Spade, 6),
  rockSlash:clone(Card.Club, 6),
  rockSlash:clone(Card.Club, 6),
  rockSlash:clone(Card.Club, 6),
  rockSlash:clone(Card.Club, 6),
  rockSlash:clone(Card.Club, 6),
}
Fk:loadTranslationTable{
  [":rock__slash"] = "基本牌<br/><b>时机</b>：出牌阶段<br/><b>目标</b>：攻击范围内的一名角色<br /><b>效果</b>：对目标角色造成1点土属性伤害。<br/>"..
  "<font color='grey'><small>（一名角色受到土属性伤害时，其可以弃置2X张牌，防止此伤害（X为伤害值）。</small></font>",
  ["#rock_damage-ask"] = "你可以弃置 %arg 张牌，防止此伤害",
}
local chargeSlashSkill = fk.CreateActiveSkill{
  name = "charge__slash_skill",
  max_phase_use_time = 1,
  target_num = 1,
  can_use = function(self, player, card, extra_data)
    return (extra_data and extra_data.bypass_times) or player.phase ~= Player.Play or
      table.find(Fk:currentRoom().alive_players, function(p)
        return self:withinTimesLimit(player, Player.HistoryPhase, card, "slash", p)
      end) and (player:getEquipment(Card.SubtypeDefensiveRide) or player:getEquipment(Card.SubtypeOffensiveRide))
  end,
  mod_target_filter = slash.skill.modTargetFilter,
  target_filter = slash.skill.targetFilter,
  on_effect = function(self, room, effect)
    local to = effect.to
    local from = effect.from
    room:damage({
      from = room:getPlayerById(from),
      to = room:getPlayerById(to),
      card = effect.card,
      damage = 2,
      damageType = Fk.NormalDamage,
      skillName = self.name
    })
  end
}
Fk:addSkill(chargeSlashSkill)
local chargeSlash = fk.CreateBasicCard{
  name = "charge__slash",
  number = 13,
  suit = Card.Spade,
  is_damage_card = true,
  skill = chargeSlashSkill,
}
extension:addCards{
  chargeSlash:clone(Card.Spade, 6),
  chargeSlash:clone(Card.Club, 6),
  chargeSlash:clone(Card.Club, 6),
  chargeSlash:clone(Card.Club, 6),
  chargeSlash:clone(Card.Club, 6),
  chargeSlash:clone(Card.Club, 6),
}
Fk:loadTranslationTable{
  [":charge__slash"] = "基本牌<br/><b>时机</b>：出牌阶段<br/><b>目标</b>：攻击范围内的一名角色<br />"..
  "<b>效果</b>：对目标角色造成2点伤害。（若你未装备坐骑，你不能使用此牌）<br/>"
}
local ironChariotSkill = fk.CreateTriggerSkill{
  name = "#iron_chariot_skill",
  attached_equip = "iron_chariot",
  frequency = Skill.Compulsory,
  events = {fk.PreCardEffect, fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if event == fk.PreCardEffect then
      return player.id == data.to and player:hasSkill(self) and data.card.name == "slash"
    else
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Card.PlayerEquip then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).sub_type == Card.SubtypeOffensiveRide then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.PreCardEffect then
      player.room:broadcastPlaySound("./packages/maneuvering/audio/card/vine")
      return true
    else
      local card = player:getEquipment(Card.SubtypeDefensiveRide)
      if card and Fk:getCardById(card).name == "iron_chariot" then
        player.room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name)
      end
    end
  end
}
Fk:addSkill(ironChariotSkill)
local ironChariot = fk.CreateDefensiveRide{
  name = "iron_chariot",
  suit = Card.Club,
  number = 10,
  equip_skill = ironChariotSkill,
  on_install = function(self, room, player)
    DefensiveRide.onInstall(self, room, player) 
    if player:isAlive() then
      local card = player:getEquipment(Card.SubtypeOffensiveRide)
      if card then
        player.room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name)
      end
    end
  end,
}
extension:addCard(ironChariot)
Fk:loadTranslationTable{
  ["#iron_chariot_skill"] = "铁骑马车",
  [":iron_chariot"] = "装备牌·坐骑<br /><b>坐骑技能</b>：其他角色与你的距离+1。【铁骑马车】与进攻坐骑牌在装备区里互斥；若你未横置，普通【杀】对你无效。",
}
Fk:loadTranslationTable{
  ["rock__slash"] = "岩杀",
  ["charge__slash"] = "冲杀",
  ["iron_chariot"] = "铁骑马车",

}

return extension